package com.cxh.service.impl;

import com.cxh.base.Data1ServiceImpl;
import com.cxh.base.Data2ServiceImpl;
import com.cxh.util.DataSource;
import com.cxh.dao.CmdCollectionDao;
import com.cxh.entity.CmdCollection;
import com.cxh.service.CmdCollectionService;
import com.cxh.util.CommonUtility;
import com.shimne.util.NumberUtil;
import com.shimne.util.ObjectUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 类说明：
 * @author  ChenXH
 * @date  2019-01-04 16:06:48
 */
@Service("cmdCollectionService")
@DataSource("dataSource1")
public class CmdCollectionServiceImpl extends Data1ServiceImpl<CmdCollection> implements CmdCollectionService {
    @Autowired
    private CmdCollectionDao dao;


    @Override
    public List<CmdCollection> loadPageList(Map<String, Object> map) {
       return null;
    }
    
    @Override
    public Map<String, Object> loadCmdMap(int cmdId, String mapUrl) {
		
		// 返回的Map
		Map<String, Object> cmdMap = new HashMap<String, Object>();
				
		if(!ObjectUtil.isNull(cmdId) &&  cmdId > 0){
			// 根据Id获取命令集
			Map<String, Object> cmd = dao.loadCmd(cmdId);
			if(ObjectUtil.isNull(cmd)){
				return null;
			}
			if(!ObjectUtil.isNull(cmd.get("cmdname")) && !ObjectUtil.isEmpty(cmd.get("cmdname"))){
				cmdMap.put("cmdName", cmd.get("cmdname"));
			}else{
				cmdMap.put("cmdName", "");
			}
			if(!ObjectUtil.isNull(cmd.get("mapid")) && !ObjectUtil.isEmpty(cmd.get("mapid"))){
				cmdMap.put("mapId",ObjectUtil.isNull(cmd.get("mapid"))?0:NumberUtil.parseInt(cmd.get("mapid")+""));
			}else{
				cmdMap.put("mapId", 0);
			}
			if(!ObjectUtil.isNull(cmd.get("mapname")) && !ObjectUtil.isEmpty(cmd.get("mapname"))){
				cmdMap.put("mapName", cmd.get("mapname"));
			}else{
				cmdMap.put("mapName", "");
			}
			if(!ObjectUtil.isNull(cmd.get("url")) && !ObjectUtil.isEmpty(cmd.get("url"))){
				mapUrl += cmd.get("url");
				cmdMap.put("mapUrl", mapUrl);
			}else{
				cmdMap.put("mapUrl", "");
			}
			cmdMap.put("circulation", cmd.get("circulation"));
			
			// 命令集绑定的
			List<Map<String, Object>> unitList = dao.loadUnitByCmd(cmdId);
			if(!ObjectUtil.isNull(unitList) && unitList.size() > 0){
				cmdMap.put("cmdList", unitList);
			}
		}
		
		return cmdMap;
	}

}
